const { Types } = require("mongoose");
const mongoose = require("./db");
//用户列表
let userSchema = new mongoose.Schema({
        username:String,
        password:String,
        email:String,
        phone:String,
})
//患者分组表单
let groupSchema = new mongoose.Schema({
        name:String,
})

//患者列表
let AdmissionsSchema = new mongoose.Schema({
        name:String,
        sex:String,
        age:Number,
        starttime:Date,//开始时间
        endtime:Date,//结束时间
        phone:Number,//电话号码
        idcard:String,//身份证号
        address:String,//地址
        shichang:String,//时长
        description:String,//描述状态
        status:String,//状态
        imgs:Array,
        userinfoid:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },//关联医生表
        medical:{
                type:[mongoose.Types.ObjectId],
                ref:'medical'
        },//关联处方表
        group:{
                type:mongoose.Types.ObjectId,
                ref:'group'
        },//关联患者分组表
})

//处方列表
let medicalSchema = new mongoose.Schema({
       name:String,
       price:Number,
       description:String,
       imgs:Array,
       usageDosage:String,//用法用量
       status:String,//状态
       userinfoid:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },//关联医生表
        admissions:{
                type:[mongoose.Types.ObjectId],
                ref:'admissions'
        },//关联患者表
})

//药品科室列表
let departmentSchema = new mongoose.Schema({
        name:String,
})

//药品分类列表
let categorySchema = new mongoose.Schema({
        name:String,
        departmentid:{
                type:mongoose.Types.ObjectId,
                ref:'department'
        },//关联药品科室表
})
//药品列表
let drugSchema = new mongoose.Schema({
        name:String,
        price:Number,
        num:Number,
        description:String,//备注
        notice:String,//注意事项
        composition:String,//成分
        effect:String,//作用类别
        symptom:String,//适应症状
        taboo:String,//禁忌
        adverseReactions:String,//不良反应
        packing:String,//包装
        dosageForm:String,//剂型
        specification:String,//规格
        productionEnterprise:String,//生产企业
        approvalNumber:String,//批准文号
        validityPeriod:String,//有效期
        storageConditions:String,//储存条件
        useMethod:String,tion:String, //使用方法
        drugInteraction:String,//药物相互作用
        imgs:Array,
        usageDosage:String,//用法用量
        status:String,//状态
        categoryid:{
                type:mongoose.Types.ObjectId,
                ref:'category'
        },//关联药品分类表
        frequency:{
                type:mongoose.Types.ObjectId,
                ref:'frequency'
        },//关联用药频次表
        once:{
                type:mongoose.Types.ObjectId,
                ref:'once'
        },//关联单次用药表
        method:{
                type:mongoose.Types.ObjectId,
                ref:'method'
        },//关联用药方法表
})
//用药频次表
let frequencySchema = new mongoose.Schema({
        name:String,
})
//单次用药表
let onceSchema = new mongoose.Schema({
        name:String,
})
//用药方法表
let methodSchema = new mongoose.Schema({
        name:String,
})

//创作中心列表
let articleSchema = new mongoose.Schema({
        title:String,
        content:String,
        imgs:Array,
        status:String,
        url:String,//视频地址
        type:String,
        time:Date,//发布时间
        topic:{
                type:mongoose.Types.ObjectId,
                ref:'topic'
        },//关联话题表
        userinfoid:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },//关联医生表
})
//草稿箱列表
let draftSchema = new mongoose.Schema({
        title:String,
        content:String,
        imgs:Array,
        status:String,
        url:String,//视频地址
        type:String,
        time:Date,//发布时间
        topic:{
                type:mongoose.Types.ObjectId,
                ref:'topic'
        },//关联话题表
        userinfoid:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },//关联医生表
})
//话题列表
let topicSchema = new mongoose.Schema({
        title:String,
})

//群发消息历史列表
let messageSchema = new mongoose.Schema({
        content:String,
        status:String,
        time:Date,//发布时间
        //关联患者表
        Admissions:{
                type:mongoose.Types.ObjectId,
                ref:'Admissions'
        },
})

//个人信息表
let userinfoSchema = new mongoose.Schema({
        name:String,
        phone:String,
        email:String,
        password:String,
        sex:String,
        age:Number,
        address:String,
        imgs:String,
        userinfoid:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },//关联医生表
        hospital:{
                type:mongoose.Types.ObjectId,
                ref:'hospital'
        },//关联医院表
        departmentSubject:{
                type:mongoose.Types.ObjectId,
                ref:'departmentSubject'
        },//关联科室科目表

})
//地址表
let addressSchema = new mongoose.Schema({
        name:String,
})

//区域表
let areaSchema = new mongoose.Schema({
        name:String,
        addressid:{
                type:mongoose.Types.ObjectId,
                ref:'address'
        },//关联地址表
})
//医院表
let hospitalSchema = new mongoose.Schema({
        name:String,
        area:{
                type:mongoose.Types.ObjectId,
                ref:'area'
        },//关联区表
})

//科室分类表
let departmentClassSchema = new mongoose.Schema({
        name:String,
})
//科室科目表
let departmentSubjectSchema = new mongoose.Schema({
        name:String,
        departmentClassid:{
                type:mongoose.Types.ObjectId,
                ref:'departmentClass'
        },//关联科室分类表
})
//订单明细表
let orderDetailSchema = new mongoose.Schema({
        name:String,
        price:Number,
        createtime:Date,//创建时间
        paytime:Date,//支付时间
        refundtime:Date,//退款时间
        refundway:String,//退款方式
        paytype:String,//支付类型
        orderamount:Number,//订单金额
        ordernum:String,//订单编号
        status:String,//状态
        //关联患者表
        Admissions:{
                type:mongoose.Types.ObjectId,
                ref:'Admissions'
        },
        //关联医生表
        userinfo:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },
})

//评价表
let evaluateSchema = new mongoose.Schema({
        content:String,
        createtime:Date,//创建时间
        score:Number,//评分
        //关联患者表
        Admissions:{
                type:mongoose.Types.ObjectId,
                ref:'Admissions'
        },
        //关联医生表
        userinfo:{
                type:mongoose.Types.ObjectId,
                ref:'userinfo'
        },
})
//常用语表
let commonSchema = new mongoose.Schema({
        content:String,
})




//用户表
let userModel=mongoose.model('user',userSchema,'user')
//用户信息表
let userinfoModel=mongoose.model('userinfo',userinfoSchema,'userinfo')
//地址表
let addressModel=mongoose.model('address',addressSchema,'address')
//区域表
let areaModel=mongoose.model('area',areaSchema,'area')
//医院表
let hospitalModel=mongoose.model('hospital',hospitalSchema,'hospital')
//科室分类表
let departmentClassModel=mongoose.model('departmentClass',departmentClassSchema,'departmentClass')
//科室科目表
let departmentSubjectModel=mongoose.model('departmentSubject',departmentSubjectSchema,'departmentSubject')
//订单明细表
let orderDetailModel=mongoose.model('orderDetail',orderDetailSchema,'orderDetail')
//评价表
let evaluateModel=mongoose.model('evaluate',evaluateSchema,'evaluate')
//常用语表
let commonModel=mongoose.model('common',commonSchema,'common')
//用户列表
let AdmissionsModel=mongoose.model('Admissions',AdmissionsSchema,'Admissions')
//处方列表
let medicalModel=mongoose.model('medical',medicalSchema,'medical')
//药品科室列表
let departmentModel=mongoose.model('department',departmentSchema,'department')
//药品分类列表
let categoryModel=mongoose.model('category',categorySchema,'category')
//药品列表
let drugModel=mongoose.model('drug',drugSchema,'drug')
//用药频次表
let frequencyModel=mongoose.model('frequency',frequencySchema,'frequency')
//单次用药表
let onceModel=mongoose.model('once',onceSchema,'once')
//用药方法表
let methodModel=mongoose.model('method',methodSchema,'method')
//创作中心列表
let articleModel=mongoose.model('article',articleSchema,'article')
//草稿箱列表
let draftModel=mongoose.model('draft',draftSchema,'draft')
//话题列表
let topicModel=mongoose.model('topic',topicSchema,'topic')
//群发消息历史列表
let messageModel=mongoose.model('message',messageSchema,'message')
//患者分组表单
let groupModel=mongoose.model('group',groupSchema,'group')



module.exports = 
        {
           userModel,
           userinfoModel,
           addressModel,
           areaModel,
           hospitalModel,
           departmentClassModel,
           departmentSubjectModel,
           orderDetailModel,
           evaluateModel,
           commonModel,
           AdmissionsModel,
           medicalModel,
           departmentModel,
           categoryModel,
           drugModel,
           frequencyModel,
           onceModel,
           methodModel,
           articleModel,
           draftModel,
           topicModel,
           messageModel,
           groupModel
        };
